﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace iNoteIt.Plugin
{
    public class PluginService
    {
        internal static PluginService ServiceInst;

        public static PluginService Instance
        {
            get
            {
                if (ServiceInst == null)
                    return ServiceInst = new PluginService();
                else
                    return ServiceInst;
            }
        }

        internal List<ILoadScopeServiceGenerator> LoadScopeServiceGenerators { get; } =
            new List<ILoadScopeServiceGenerator>();

        internal List<IUnloadScopeServiceGenerator> UnloadScopeServiceGenerators { get; } =
            new List<IUnloadScopeServiceGenerator>();

        public void RegisterLoadScopeServiceGenerator(ILoadScopeServiceGenerator generator)
        {
            if (generator == null)
                throw new ArgumentNullException(nameof(generator));

            if (LoadScopeServiceGenerators.Contains(generator))
                return;

            LoadScopeServiceGenerators.Add(generator);
        }

        public void RegisterUnloadScopeServiceGenerator(IUnloadScopeServiceGenerator generator)
        {
            if(generator == null)
                throw new ArgumentNullException(nameof(generator));

            if (UnloadScopeServiceGenerators.Contains(generator))
                return;

            UnloadScopeServiceGenerators.Add(generator);
        }

        public void UnregisterLoadScopeServiceGenerator(ILoadScopeServiceGenerator generator)
        {
            if(generator==null || !LoadScopeServiceGenerators.Contains(generator))
                return;

            LoadScopeServiceGenerators.Remove(generator);
        }

        public void UnregisterUnloadScopeServiceGenerator(IUnloadScopeServiceGenerator generator)
        {
            if (generator == null || !UnloadScopeServiceGenerators.Contains(generator))
                return;

            UnloadScopeServiceGenerators.Remove(generator);
        }


        

        
    }
}
